home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / signal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-12  |  3.3 KB  |  137 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: signal.c,v 1.4 1996/08/13 13:56:09 digulla Exp $
  4.     $Log: signal.c,v $
  5.     Revision 1.4  1996/08/13 13:56:09  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.3  1996/08/01 17:41:20  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang: english
  15. */
  16. #include <exec/execbase.h>
  17. #include <aros/libcall.h>
  18.  
  19. /*****************************************************************************
  20.  
  21.     NAME */
  22.     #include <clib/exec_protos.h>
  23.  
  24.     __AROS_LH2(void, Signal,
  25.  
  26. /*  SYNOPSIS */
  27.     __AROS_LHA(struct Task *,     task,      A1),
  28.     __AROS_LHA(ULONG,             signalSet, D0),
  29.  
  30. /*  LOCATION */
  31.     struct ExecBase *, SysBase, 54, Exec)
  32.  
  33. /*  FUNCTION
  34.     Send some signals to a given task. If the task is currently waiting
  35.     on these signals, has a higher priority as the current one and if
  36.     taskswitches are allowed the new task begins to run immediately.
  37.  
  38.     INPUTS
  39.     task      - Pointer to task structure.
  40.     signalSet - The set of signals to send to the task.
  41.  
  42.     RESULT
  43.  
  44.     NOTES
  45.     This function may be used from interrupts.
  46.  
  47.     EXAMPLE
  48.  
  49.     BUGS
  50.  
  51.     SEE ALSO
  52.     AllocSignal(), FreeSignal(), Wait(), SetSignal(), SetExcept()
  53.  
  54.     INTERNALS
  55.  
  56.     HISTORY
  57.  
  58. ******************************************************************************/
  59. {
  60.     __AROS_FUNC_INIT
  61.  
  62.     /* Protect the task lists against other tasks that may use Signal(). */
  63.     Disable();
  64.  
  65.     /* Set the signals in the task structure. */
  66.     task->tc_SigRecvd|=signalSet;
  67.  
  68.     /* Do those bits raise exceptions? */
  69.     if(task->tc_SigExcept&task->tc_SigRecvd)
  70.     {
  71.     /* Yes. Set the exception flag. */
  72.     task->tc_Flags|=TF_EXCEPT;
  73.  
  74.     /* task is running? Raise the exception or defer it for later. */
  75.     if(task->tc_State==TS_RUN)
  76.     {
  77.         /* Are taskswitches allowed? (Don't count own Disable() here) */
  78.         if(SysBase->TDNestCnt>=0||SysBase->IDNestCnt>0)
  79.         /* No. Store it for later. */
  80.         SysBase->AttnResched|=0x80;
  81.         else
  82.         {
  83.         /* Switches are allowed. Move the current task away. */
  84.         SysBase->ThisTask->tc_State=TS_READY;
  85.         Enqueue(&SysBase->TaskReady,&SysBase->ThisTask->tc_Node);
  86.  
  87.         /* And force a rescedule. */
  88.         Switch();
  89.         }
  90.  
  91.         /* All done. */
  92.         Enable();
  93.         return;
  94.     }
  95.     }
  96.  
  97.     /*
  98.     Is the task receiving the signals waiting on them
  99.     (or on a exception) ?
  100.     */
  101.     if(task->tc_State==TS_WAIT&&
  102.        (task->tc_SigRecvd&(task->tc_SigWait|task->tc_SigExcept)))
  103.     {
  104.     /* Yes. Move him to the ready list. */
  105.     task->tc_State=TS_READY;
  106.     Remove(&task->tc_Node);
  107.     Enqueue(&SysBase->TaskReady,&task->tc_Node);
  108.  
  109.     /* Has it a higher priority as the current one? */
  110.     if(task->tc_Node.ln_Pri>SysBase->ThisTask->tc_Node.ln_Pri)
  111.         /*
  112.         Yes. A taskswitch is necessary. Prepare one if possible.
  113.         (If the current task is not running it is already moved)
  114.         */
  115.         if(SysBase->ThisTask->tc_State==TS_RUN)
  116.         {
  117.         /* Are taskswitches allowed? */
  118.         if(SysBase->TDNestCnt>=0||SysBase->IDNestCnt>0)
  119.             /* No. Store it for later. */
  120.             SysBase->AttnResched|=0x80;
  121.         else
  122.         {
  123.             /* Switches are allowed. Move the current task away. */
  124.             SysBase->ThisTask->tc_State=TS_READY;
  125.             Enqueue(&SysBase->TaskReady,&SysBase->ThisTask->tc_Node);
  126.  
  127.             /* And force a rescedule. */
  128.             Switch();
  129.         }
  130.         }
  131.     }
  132.  
  133.     Enable();
  134.     __AROS_FUNC_EXIT
  135. }
  136.  
  137.